package com.example.xy_assistant;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.example.xy_assistant.adapter.PictureAdapter;

import java.util.ArrayList;
import java.util.List;

public class PictureActivity extends AppCompatActivity implements View.OnClickListener {

    private ViewPager view_pager;
    private Button btn_to1;
    private Button btn_to2;
    private Button btn_to3;
    private Button btn_to4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_picture);
        initView();
        initData();
    }

    private void initData() {
        List<Integer> list = new ArrayList<>();
        list.add(R.drawable.ad01);
        list.add(R.drawable.ad02);
        list.add(R.drawable.ad03);
        list.add(R.drawable.ad04);
        PictureAdapter pictureAdapter = new PictureAdapter(this, list);
        view_pager.setAdapter(pictureAdapter);
    }

    private void initView() {
        view_pager = (ViewPager) findViewById(R.id.view_pager);
        btn_to1 = (Button) findViewById(R.id.btn_to1);
        btn_to1.setOnClickListener(this);
        btn_to2 = (Button) findViewById(R.id.btn_to2);
        btn_to2.setOnClickListener(this);
        btn_to3 = (Button) findViewById(R.id.btn_to3);
        btn_to3.setOnClickListener(this);
        btn_to4 = (Button) findViewById(R.id.btn_to4);
        btn_to4.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_to1:
                view_pager.setCurrentItem(0);
                break;
            case R.id.btn_to2:
                view_pager.setCurrentItem(1);
                break;
            case R.id.btn_to3:
                view_pager.setCurrentItem(2);
                break;
            case R.id.btn_to4:
                view_pager.setCurrentItem(3);
                break;
        }
    }
}